import json
import numpy as np


def json_to_dict_items(json_file_path):
    # 读取 JSON 文件
    with open(json_file_path, 'r') as file:
        data = json.load(file)
        print(data)

    # 假设 JSON 文件中的 "matrix" 键对应矩阵数据
    matrix = data.get("matrix", {})
    print(matrix)

    # 创建一个空字典来存储矩阵元素的索引和值
    result_dict = {}
    rows = len(matrix)
    if rows > 0:
        columns = len(matrix[0])
    else:
        columns = 0

    # 遍历矩阵的每个元素
    for i in range(rows):
        for j in range(columns):
            result_dict[(i, j)] = np.float64(matrix[i][j])

    # 获取字典的 dict_items 对象
    result_items = result_dict.items()

    return result_items


# 示例调用
json_file_path = 'traffic_simulation.json'
items = json_to_dict_items(json_file_path)
for item in items:
    print(item)